package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SMenu;
import com.ruoyi.system.service.ISMenuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜单编辑Controller
 * 
 * @author yu
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/smenu")
public class SMenuController extends BaseController
{
    @Autowired
    private ISMenuService sMenuService;

    /**
     * 查询菜单编辑列表
     */
    @PreAuthorize("@ss.hasPermi('system:smenu:list')")
    @GetMapping("/list")
    public TableDataInfo list(SMenu sMenu)
    {
        startPage();
        List<SMenu> list = sMenuService.selectSMenuList(sMenu);
        return getDataTable(list);
    }

    /**
     * 导出菜单编辑列表
     */
    @PreAuthorize("@ss.hasPermi('system:smenu:export')")
    @Log(title = "菜单编辑", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SMenu sMenu)
    {
        List<SMenu> list = sMenuService.selectSMenuList(sMenu);
        ExcelUtil<SMenu> util = new ExcelUtil<SMenu>(SMenu.class);
        util.exportExcel(response, list, "菜单编辑数据");
    }

    /**
     * 获取菜单编辑详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:smenu:query')")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable("menuId") Long menuId)
    {
        return success(sMenuService.selectSMenuByMenuId(menuId));
    }

    /**
     * 新增菜单编辑
     */
    @PreAuthorize("@ss.hasPermi('system:smenu:add')")
    @Log(title = "菜单编辑", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SMenu sMenu)
    {
        return toAjax(sMenuService.insertSMenu(sMenu));
    }

    /**
     * 修改菜单编辑
     */
    @PreAuthorize("@ss.hasPermi('system:smenu:edit')")
    @Log(title = "菜单编辑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SMenu sMenu)
    {
        return toAjax(sMenuService.updateSMenu(sMenu));
    }

    /**
     * 删除菜单编辑
     */
    @PreAuthorize("@ss.hasPermi('system:smenu:remove')")
    @Log(title = "菜单编辑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public AjaxResult remove(@PathVariable Long[] menuIds)
    {
        return toAjax(sMenuService.deleteSMenuByMenuIds(menuIds));
    }
}
